'use client';

import {strategyArmory} from "@/apis";

export default function StrategyArmoryButton() {
    const handleClick = async () => {
        const queryParams = new URLSearchParams(window.location.search);
        const activityId = Number(queryParams.get("activityId"));
        if (!activityId) {
            window.alert("在请求地址中配置 activityId 的值");
            return;
        }
        const res = await strategyArmory(activityId);
        const {code, info} = await res.json();
        if (code !== "0000") {
            window.alert("抽奖策略装配失败 code: " + code + " info: " + info);
            return;
        }
        window.alert("抽奖策略装配成功！");
    };

    return (
        <div
            className="px-6 py-2 mb-8 text-white bg-yellow-600 rounded-full shadow-lg hover:bg-yellow-800 focus:outline-none focus:ring-2 focus:ring-blue-300"
            style={{cursor: "pointer"}}
            onClick={handleClick}
        >
            装配抽奖「测试前点击预热数据」
        </div>
    );
}
